home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / MotifApp / ch2 / Stopwatch2 / Face.C < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-03  |  2.0 KB  |  69 lines

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //////////////////////////////////////////////////////////////////////////////
  3. //         This example code is from the book:
  4. //
  5. //           Object-Oriented Programming with C++ and OSF/Motif
  6. //         by
  7. //           Douglas Young
  8. //           Prentice Hall, 1992
  9. //           ISBN 0-13-630252-1    
  10. //
  11. //         Copyright 1991 by Prentice Hall
  12. //         All Rights Reserved
  13. //
  14. //  Permission to use, copy, modify, and distribute this software for 
  15. //  any purpose except publication and without fee is hereby granted, provided 
  16. //  that the above copyright notice appear in all copies of the software.
  17. ///////////////////////////////////////////////////////////////////////////////
  18. //////////////////////////////////////////////////////////////////////////////
  19.  
  20.  
  21. ///////////////////////////////////////////////////////
  22. // Face.C: A simple digital clock face for a stop watch
  23. ////////////////////////////////////////////////////////
  24. #include "Face.h"
  25. #include <Xm/Xm.h>
  26. #include <Xm/RowColumn.h>
  27. #include <Xm/Label.h>
  28. #include <Xm/Frame.h>
  29. #include <stdio.h>
  30.  
  31. Face::Face ( Widget parent, char *name ) : BasicComponent ( name )
  32. {
  33.     // Create all widgets
  34.     
  35.     _w = XmCreateRowColumn ( parent, _name, NULL, 0 );
  36.     
  37.     _label = XtCreateManagedWidget ( "label", 
  38.                     xmLabelWidgetClass, 
  39.                     _w, NULL, 0 );
  40.     _frame = XtCreateManagedWidget ( "frame", 
  41.                     xmFrameWidgetClass, 
  42.                     _w, NULL, 0 );     
  43.     _time  = XtCreateManagedWidget ( "time", 
  44.                     xmLabelWidgetClass, 
  45.                     _frame, NULL, 0 );
  46. }
  47.  
  48. void Face::setTime ( float value )
  49. {
  50.     char     buf[50];
  51.     XmString xmstr;
  52.     
  53.     // Format value as a string
  54.     
  55.     sprintf ( buf, "%6.3f", value ); 
  56.     
  57.     // Convert to compound string
  58.     
  59.     xmstr = XmStringCreateSimple ( buf ); 
  60.     
  61.     // Display the string in the XmLabel widget
  62.     
  63.     XtVaSetValues ( _time, XmNlabelString, xmstr, NULL );
  64.     
  65.     // The compound string can be freed once passed to the widget
  66.     
  67.     XmStringFree ( xmstr );
  68. }
  69.